require(['monitor'], function () {

    $('#monitor').monitor({
        canId: '11',
        callback: function (data) {
            loadData(data);
        },
        clearData: function () {
            loadData({});
        }
    });
    //充电系统工作状态
    function setChargeStText(el, value) {
        $(el).setView(value, [
            {value: 0, text: '初始化'},
            {value: 1, text: '充电准备就绪'},
            {value: 2, text: '充电开始'},
            {value: 3, text: '充电结束'},
            {value: 4, text: '充电暂停'},
            {value: 5, text: '充电停止'},
            {value: 6, text: '默认驱动电机状态'}
        ], {unMatchConfig: {text: '-'}});
    }
    //充电连接状态
    function setChargeLinkStText(el, value) {
        $(el).setView(value, [
            {value: 0, text: '未连接'},
            {value: 1, text: '连接正常'},
            {value: 2, text: '连接故障'}
        ], {unMatchConfig: {text: '-'}});
    }
    //充电系统故障状态
    function setChargeErrorStText(el, value) {
        $(el).setView(value, [
            {value: 0, text: '正常'},
            {value: 1, text: '供电故障（停电）'},
            {value: 2, text: '控制器故障'},
            {value: 3, text: '控制器过问'},
            {value: 4, text: '交流外充设备故障'},
            {value: 5, text: '动力电池故障'},
            {value: 6, text: 'DC启动异常'}
        ], {unMatchConfig: {text: '-'}});
    }


    function loadData(data) {
        if (!$.isEmptyObject(data)) {
            $("#totalVoltage").html(data.totalVoltage || '-');
            $("#chargeDisCharCurrent").html(data.chargeDisCharCurrent || '-');
            $("#soc").html(data.soc || '-' + "%");
            $("#totalMileage").html(data.totalMileage || '-');
            $("#highestBatteryVoltage").html(data.highestBatteryVoltage || '-');
            $("#highestVoltageBoxNO").html(data.highestVoltageBoxNO || '-');
            $("#lowestBatteryVoltage").html(data.lowestBatteryVoltage || '-');
            $("#lowestVoltageBoxNO").html(data.lowestVoltageBoxNO || '-');
            $("#highestTemperature").html(data.highestTemperature || '-');
            $("#highestTemperatureBoxNO").html(data.highestTemperatureBoxNO || '-');
            $("#lowestTemperature").html(data.lowestTemperature || '-');
            $("#lowestTemperatureBoxNO").html(data.lowestTemperatureBoxNO || '-');
            $("#lChargeSt").html(data.lChargeSt || '-');
            //左充电系统工作状态
            setChargeStText("#lChargeSt",data.lChargeSt || -1);
            //右充电系统工作状态
            setChargeStText("#rChargeSt",data.rChargeSt || -1);
            //左充电连接状态
            setChargeLinkStText("#lChargeLinkSt",data.lChargeLinkSt || -1);
            //右充电连接状态
            setChargeLinkStText("#rChargeLinkSt",data.rChargeLinkSt || -1);
            //左充电系统故障状态
            setChargeErrorStText("#lChargeErrorSt",data.lChargeErrorSt || -1);
            //右充电系统故障状态
            setChargeErrorStText("#rChargeErrorSt",data.rChargeErrorSt || -1);
            //电池组温度状态
            $("#btryPackTeptSt").setView(data.btryPackTeptSt || -1, [
                {value: 0, text: '正常'},
                {value: 1, text: '电池组温度一般报警'},
                {value: 2, text: '电池组温度超高报警'}
            ], {unMatchConfig: {text: '-'}});
            //漏电状态
            $("#leakageSt").setView(data.leakageSt || -1, [
                {value: 0, text: '正常'},
                {value: 1, text: '严重漏电报警'}
            ], {unMatchConfig: {text: '-'}});
        }
    }

});